/**
* @brief 主程序入口
* 初始化系统，运行状态机主循环
*/
#include "menu.h"

int dev_id_min = 10000;// 设备ID起始值
int main()
{
	// 加载设备数据到链表
	node_t *head = load_dev();
	if(head == NULL)
	{
		printf("create dlist error\n");
		return 0;
	}
	// 状态机主循环
	MenuState state = WELCOME_STATE;
	while (state != EXIT_STATE) 
	{
		switch (state)
		{
		case WELCOME_STATE:
			state = welcome_menu(head);// 欢迎界面
			break;
		case LOGIN_STATE:
			state = login_menu(head);// 登录界面
			break;
		case ADMIN_STATE:
			state = admin_menu(head);// 管理主菜单
			break;
		case ADD_STATE:
			state = add_dev_menu(head);// 添加设备
			break;
		case DEL_STATE:
			state = del_dev_menu(head);// 删除设备
			break;
		case UPDATE_STATE:
			state = update_dev_menu(head);// 更新设备
			break;
		case SHOW_STATE:
			state = show_dev_menu(head);// 显示设备
			break;
		case FIND_STATE:
			state = find_dev_menu(head);// 查找设备
			break;
		case EXIT_STATE:
			exit(0);// 退出程序
		default:
			break;
		}
	}
	// 程序退出前保存数据并清理链表
	save_dev(head);
	destroy_dlist(&head);
	return 0;
}
